<template>
  <h1>员工列表练习</h1>
  <input type="text" placeholder="请输入员工姓名" v-model="worker.name">
  <input type="text" placeholder="请输入员工工资" v-model="worker.salary">
  <input type="text" placeholder="请输入员工岗位" v-model="worker.job">
  <hr>
  <button @click="add()">点我添加</button>
  <hr>
  <table border="1" style="border-collapse: collapse">
    <tr>
      <th>编号</th>
      <th>员工姓名</th>
      <th>员工工资</th>
      <th>员工岗位</th>
    </tr>
    <tr v-for="(worker,index) in workersData">
      <td>{{index+1}}</td>
      <td>{{worker.name}}</td>
      <td>{{worker.salary}}</td>
      <td>{{worker.job}}</td>
    </tr>
  </table>
</template>

<script setup>
  import {ref} from 'vue';
  let workersData =ref([]);
  let worker =ref({name:"",salary:"",job:""});
  const add =()=>{
      // let newworker ={
      //   name:worker.value.name,
      //   salary:worker.value.salary,
      //   job:worker.value.job
      // };
      workersData.value.push(worker.value);
      // console.log(workersData._rawValue);
      worker.value ={name:'',salary:'',job:''};
  }
</script>


<style scoped>

</style>